import './polyfill';
import App from './App.vue';
import './style.css';
import { createApp } from 'vue';
import { setupStore } from '@/store';
import { setupRouter } from '@/router';
import { setupIcons } from './components/basic/icon/icons.data';
import { setupI18n } from './locales';
import { setupAssets, setupElem, setupGlobalMethods } from './plugins';
import 'element-plus/dist/index.css';

const app = createApp(App);

function setupPlugins() {
  // 安装图标
  setupIcons();
  // 注册全局常用的组件
  setupElem(app);
  // 引入静态资源
  setupAssets();
  // 注册全局方法，如：app.config.globalProperties.$message = message
  setupGlobalMethods(app);
}

async function setupApp() {
  if (import.meta.env.VITE_MOCK_IN_PROD === 'true') {
    // const { setupMock } = await import('../mocks/');
    // // 启用 mock
    // await setupMock();
  }

  setupStore(app);
  // Multilingual configuration
  // Asynchronous case: language files may be obtained from the server side
  await setupI18n(app);

  await setupRouter(app);

  app.mount('#app'); // mount app
}

setupPlugins();

setupApp();
